package com.zhoux.collections.map;

import java.util.HashMap;
import java.util.Scanner;

/**
 * @author taoyi
 * @version 1.0
 * @date 2021/3/20 8:43
 *
 * 本类用于统计用户输入字符出现的次数
 */
public class HashMap_Test3 {
    public static void main(String[] args) {
        System.out.println("请输入字符串：");
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        HashMap<Character,Integer> map = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            Character key = s.charAt(i);
            Integer value = map.get(key);
            if (value==null){
                map.put(key,1);
            }else {
                map.put(key,++value);
            }
        }
        System.out.println(map);
    }
}
